package com.qf.osmorder.order.controller;

import com.qf.common.core.annotation.NoLogin;
import com.qf.common.core.common.R;
import com.qf.common.pay.dto.PayDTO;
import com.qf.common.pay.param.RefundParam;
import com.qf.osmorder.order.dto.RechargeOrderDTO;
import com.qf.osmorder.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author TianWenHe
 * @date 2025/6/11
 * @desc
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("/recharge/add")
    public R addRechargeOrder(@RequestBody RechargeOrderDTO rechargeOrderDTO){
        String orderNo = orderService.addRechargeOrder(rechargeOrderDTO);
        return R.ok(orderNo);
    }

    @PostMapping("/pay")
    public R prePay(@RequestBody PayDTO payDTO) {
        String result = orderService.prePay(payDTO);
        return R.ok(result);
    }

    @NoLogin
    @PostMapping("/pay/alinotify")
    public void aliNotify(HttpServletRequest request, HttpServletResponse response) {
        orderService.notify(request,response);
    }

    @PostMapping("/refund")
    public R refundOrder(@RequestBody RefundParam refundParam) {
        String result = orderService.refundOrder(refundParam);
        return R.ok(result);
    }

    @GetMapping("/return")
    public R returnNotify(HttpServletRequest request, HttpServletResponse response) {
        orderService.returnNotify(request, response);
        return R.ok();
    }
}
